package net.zoneland.x.bpm.mobile.v1.zoneXBPM

import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import android.util.Log
import cn.jiguang.api.utils.JCollectionAuth


// [baidumap19]
// [baidumap20]
// [baidumap21]
// import com.baidu.mapapi.CoordType
// import com.baidu.mapapi.SDKInitializer
// import com.baidu.mapapi.common.BaiduMapSDKException




/**
 * Created by fancyLou on 2022-06-30.
 * Copyright © 2022 android. All rights reserved.
 */
class O2App : Application() {


    companion object {
        const val SHAREDPREFERENCESNAME = "o2oa_android_prefs"
        const val SPKEYISPRIVACY = "sp_key_privacy"
        lateinit var instance: O2App
    }



    var mContext: Context? = null

    override fun onCreate() {
        super.onCreate()
        instance = this
        mContext = applicationContext
        if (!isPrivacy()) {
            Log.i("O2APP","  privacy 还没有同意。 auth = false")
            JCollectionAuth.setAuth(this, false)
        }
        initChannel()
        Log.i("O2APP","  onCreate ====== >")
    }

    /**
     * 初始化百度 sdk
     */
    fun initBaiduSdk() {
        try {
            // [baidumap22]
            // [baidumap23]
            // [baidumap24]
            // SDKInitializer.setAgreePrivacy(this, true)
            // SDKInitializer.initialize(this)
            // SDKInitializer.setCoordType(CoordType.BD09LL)
        } catch (e: Exception) { // [baidumap25]
            Log.i("O2APP"," 百度地图初始化失败")
        }
    }

    private fun initChannel() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
            val notificationChannel = NotificationChannel(
                "o2oa_work",
                "工作通知",
                NotificationManager.IMPORTANCE_HIGH
            )
            notificationChannel.description = "待办待阅等工作相关的通知消息"
            nm.createNotificationChannel(notificationChannel)
        }
    }


    private fun isPrivacy(): Boolean {
        val pref = this.getSharedPreferences(SHAREDPREFERENCESNAME, Context.MODE_PRIVATE)
        return pref.getBoolean(SPKEYISPRIVACY, false)
    }

    fun setPrivacy() {
        val pref = this.getSharedPreferences(SHAREDPREFERENCESNAME, Context.MODE_PRIVATE)
        with(pref.edit()){
            putBoolean(SPKEYISPRIVACY, true)
            apply()
        }
        Log.i("O2APP","设置 privacy 已经同意。。。。")
    }

}